package com.ruoyi.framework.utils;

import com.ruoyi.common.core.domain.model.LoginUser;
import lombok.Data;

public class UserLocalThreadHelper {

    private static ThreadLocal<UserModel> threadLocal = new ThreadLocal<>();


    public static UserModel get(){
        return threadLocal.get();
    }

    public static boolean needEncry(){
        return get().encry;
    }

    public static void setLoginUser(LoginUser loginUser){
        check();
        get().setLoginUser(loginUser);
    }

    public static void setEncry(boolean e){
        check();
        get().setEncry(e);
    }

    public static void check(){
        UserModel userModel = threadLocal.get();
        if(userModel == null){
            userModel = new UserModel();
        }
        threadLocal.set(userModel);
    }

    @Data
    public static class UserModel{
        private boolean encry = true;

        private LoginUser loginUser;
    }

}
